#!/usr/bin/env python
# -*- coding: utf-8 -*-

from weibo import *  
import webbrowser

"""
Code to initiate connection and authentification
Could be copied and used when doing experiment~
"""

APP_KEY = '3393803453'  
APP_SECRET = 'c0493aec3a795f02d2ea28a20f27f363'  

CALLBACK_URL = 'https://api.weibo.com/oauth2/default.html'
  
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)  
url =  client.get_authorize_url()


print "If you redirect to https://api.weibo.com/oauth2/default.html?code=[code]"
print "Please input the [code] here\n"
raw_input("Press enter to continue ...")


webbrowser.open(url)

r = client.request_access_token(raw_input("input code:").strip())
client.set_access_token(r.access_token, r.expires_in)  

uid = client.account.get_uid.get()["uid"]

"""
Now we have the client object and uid

`client` is used to call sina api
`uid` is the user_id of application client
"""

import tui.ui
import curses
import locale

locale.setlocale(locale.LC_ALL, '')
encoding = locale.getpreferredencoding()

curses.wrapper(tui.ui.main, encoding, client)